package com.yw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.yw.interfaceManageInfo.dto.TestDTO;
import com.yw.interfaceManageInfo.dto.ConditionPageDTO;
import com.yw.interfaceManageInfo.dto.InterfaceManageInfoDTO;
import com.yw.interfaceManageInfo.dto.UpdateTypeBatchDTO;
import com.yw.interfaceManageInfo.vo.InterfaceManageInfoVO;
import com.yw.piliangDTO.StatusDTO;
import com.yw.result.R;
import com.yw.service.InterfaceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Slf4j
@RestController
@Tag(name = "接口管理",description = "接口管理")
@RequestMapping("/interface")
public class InterfaceController {

    @Resource
    private InterfaceService interfaceService;



    @Operation(summary = "查询单条数据")
    @GetMapping("/getOneInterface")
    public R getOneInterface(Integer id){
        return R.OK(interfaceService.oneInterface(id));
    }

    @Operation(summary = "删除接口")
    @GetMapping("/deleteInterface")
    public R deleteInterface(Integer id){
        if(interfaceService.removeById(id)){
            return R.OK();
        }else {
            return R.FAIL();
        }
    }

    @Operation(summary = "修改接口状态")
    @GetMapping("/updateStatic")
    public R updateStatic(Integer id){
        return interfaceService.updateStatic(id)?R.OK():R.FAIL();
    }


    @Operation(summary = "条件分页查询接口表")
    @PostMapping("/pageByCondition")
    public R pageByCondition(@RequestBody ConditionPageDTO conditionPageDTO){
        Page<InterfaceManageInfoVO> infoVOPage = interfaceService.pageByCondition(conditionPageDTO);
        return R.OK(infoVOPage);
    }

    @Operation(summary = "保存并退出对应接口")
    @PostMapping("/addInterface")
    public R addInterface(@RequestBody InterfaceManageInfoDTO interfaceManageInfoDTO){
        return interfaceService.saveInterface(interfaceManageInfoDTO)?R.OK():R.FAIL();
    }

    @Operation(summary = "编辑接口")
    @PostMapping("/updateInterface")
    public R updateInterface(@RequestBody InterfaceManageInfoDTO interfaceManageInfoDTO){
        return interfaceService.updateInterface(interfaceManageInfoDTO)?R.OK():R.FAIL();
    }

    //    批量发布停用
    @Operation(summary = "批量发布停用")
    @PostMapping("/batch")
    public R batch(@RequestBody StatusDTO statusDTO){
        return interfaceService.batch(statusDTO)?R.OK("批量发布成功"):R.FAIL("批量发布失败");
    }

    //    批量修改类型
    @Operation(summary = "批量修改类型")
    @PostMapping("/updateTypeBatch")
    public R updateTypeBatch(@RequestBody UpdateTypeBatchDTO updateTypeBatchDTO){
        return interfaceService.updateTypeBatch(updateTypeBatchDTO.ids,updateTypeBatchDTO.type)?R.OK("批量发布成功"):R.FAIL("批量发布失败");
    }

//    接口测试
    @Operation(summary = "接口测试")
    @PostMapping("/test")
    public R Text(@RequestBody TestDTO testDTO){
        return interfaceService.test(testDTO);
    }

//    点击接口测试跳出的界面数据
    @Operation(summary = "点击接口测试跳出的界面数据")
    @PostMapping("/testDetails")
    public R testDetails(Integer id){
        return R.OK(interfaceService.testDetails(id));
    }


    //任务管理中点击下拉框返回
    @Operation(summary = "任务管理中点击下拉框返回")
    @PostMapping("/taskGetInterface")
    public R taskGetInterface(){
        return R.OK(interfaceService.taskGetInterface());
    }

    //任务接口中返回的输入输出参数
    @Operation(summary = "任务接口中返回的输入输出参数")
    @PostMapping("/getValues")
    public R getValues(Integer id){
        return R.OK(interfaceService.getValues(id));
    }

}
